package fun.ticsmyc.question;

/**
 * @author Ticsmyc
 * @date 2021-03-09 19:23
 */
public class 旋转数组最小值二分 {
    public int findMin(int[] nums) {
        if(nums.length ==1 || nums[0] < nums[nums.length-1]){
            return nums[0];
        }

        int left=0;
        int right = nums.length-1;
        while(left < right){
            int mid = left+(right-left)/2;

            if(nums[mid] < nums[right]){
                right =mid;
            }else if(nums[mid] > nums[right]){
                left = mid+1;
            }else {
                right--;
            }
        }
        return nums[right];
    }
}
